<template>
  <v-dialog
    :title="title"
    :close-on-click-modal="false"
    v-model="visible">
    <el-form :model="inputForm" ref="inputForm" v-loading="loading" :class="method==='view'?'readonly':''"  :disabled="method==='view'" label-width="120px">
      <el-row  :gutter="15">
        <el-col :span="12">
            <el-form-item label="用户姓名" prop="name"
                :rules="[
                 ]">
              <el-input v-model="inputForm.name" placeholder="未填写用户姓名"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="登录名" prop="loginName"
                :rules="[
                 ]">
              <el-input v-model="inputForm.loginName" placeholder="未填写用户登录名"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="学校" prop="companyName"
                :rules="[
                 ]">
              <el-input v-model="inputForm.companyName" placeholder="未填写学校名"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="工会" prop="officeName"
                :rules="[
                 ]">
              <el-input v-model="inputForm.officeName" placeholder="未填写工会"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="职位" prop="roleName"
                :rules="[
                 ]">
              <el-input v-model="inputForm.roleName" placeholder="未填写职位"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="岗位" prop="postName"
                :rules="[
                 ]">
              <el-input v-model="inputForm.postName" placeholder="未填写岗位"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="申请时间" prop="applyTime"
                :rules="[
                 ]">
                <el-date-picker
                      style="width: 100%;"
                      v-model="inputForm.applyTime"
                      type="datetime"
                      value-format="YYYY-MM-DD HH:mm:ss"
                      placeholder="未填写申请时间">
                    </el-date-picker>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="处理时间" prop="dealTime"
                :rules="[
                 ]">
                <el-date-picker
                      style="width: 100%;"
                      v-model="inputForm.dealTime"
                      type="datetime"
                      value-format="YYYY-MM-DD HH:mm:ss"
                      placeholder="未处理">
                    </el-date-picker>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="处理结果" prop="result"
                :rules="[
                 ]">
              <el-input v-model="inputForm.result" placeholder="暂未处理"     ></el-input>
           </el-form-item>
        </el-col>
        
        </el-row>
    </el-form>
    <template #footer>    
        <span class="dialog-footer">
          <!-- <el-button @click="visible = false" icon="circle-close" v-if="method != 'view'">关闭</el-button> -->
          <!-- <el-button  type="primary" v-if="method != 'view'" @click="doSubmit()" icon="circle-check" v-noMoreClick>确定</el-button> -->
          <el-button  type="primary" v-if="method == 'view'" @click="agree()" icon="circle-check" v-noMoreClick>同意</el-button>
          <el-button  v-if="method == 'view'" @click="refuse()" icon="circle-close" v-noMoreClick>拒绝</el-button>
        </span>
    </template>    
  </v-dialog>
</template>

<script>
  import associationApplyService from '@/api/servicecenter/associationApplyService'
  export default {
    data () {
      return {
        title: '',
        method: '',
        visible: false,
        loading: false,
        inputForm: {
          companyDTO: {
					// 归属公司
					id: "",
					name: "",
          },
          officeDTO: {
            id: "",
            name: "",
          },
          roleIdList: [],
          postIdList: [],
          id: '',
          loginName:"",
          companyId: '',
          officeId: '',
          roleId: '',
          postId: '',
          applyTime: '',
          deaTime:'',
          result: '',
          name: '',
          companyName:'',
          officeName:'',
          roleName:'',
          postName:'',
        }
      }
    },
    components: {
    },
    created () {
    },
    methods: {
      init (method, id) {
        this.method = method
        this.inputForm.id = id
        if (method === 'add') {
          this.title = `新建会员申请数据`
        } else if (method === 'edit') {
          this.title = '修改会员申请数据'
        } else if (method === 'view') {
          this.title = '查看会员申请数据'
        }
        this.visible = true
        this.loading = false
        this.$nextTick(() => {
          this.$refs.inputForm.resetFields()
          if (method === 'edit' || method === 'view') { // 修改或者查看
            this.loading = true
            associationApplyService.queryById(this.inputForm.id).then((data) => {
              this.inputForm = this.recover(this.inputForm, data)
              this.loading = false
            })
          }
        })
      },
      // 表单提交
      doSubmit () {
        this.$refs['inputForm'].validate((valid) => {
          if (valid) {
            this.loading = true
            associationApplyService.save(this.inputForm).then((data) => {
              this.visible = false
              this.$message.success(data)
              this.$emit('refreshDataList')
              this.loading = false
            }).catch(() => {
              this.loading = false
            })
          }
        })
      },
      agree(){
        this.loading = true
        this.inputForm.companyDTO.id=this.inputForm.companyId
        this.inputForm.officeDTO.id=this.inputForm.officeId
        this.inputForm.roleIdList=[this.inputForm.roleId]
        this.inputForm.postIdList=[this.inputForm.postId]
        associationApplyService.agree(this.inputForm)
        .then((data)=>{
          this.visible = false
          this.loading = false
          this.$message.success(data)
          this.$emit('refreshDataList')
        }).catch(()=>{
          this.loading = false
        })
      },
      refuse(){
        this.loading = true
        console.log(this.inputForm.id)
        associationApplyService.refuse(this.inputForm.id)
        .then((data)=>{
          this.visible = false
          this.loading = false
          this.$message.success(data)
          this.$emit('refreshDataList')
        }).catch(()=>{
          this.loading = false
        })
      }
    }
  }
</script>

  
